<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>4-7</title>
    <style>
        body,div,ul,li,p{margin:0;padding:0;}
        body{color:#666;font:12px/1.5 Arial;}
        ul{list-style-type:none;}
        #star{position:relative;width:600px;margin:10px auto;}
        #star ul,#star span{float:left;display:inline;height:19px;line-height:19px;}
        #star ul{margin:0 10px;}
        #star li{float:left;width:24px;cursor:pointer;text-indent:-9999px;background:url(../img/star.png) no-repeat;}
        #star strong{color:#f60;padding-left:10px;}
        #star li.on{background-position:0 -28px;}
        #star p{position:absolute;top:20px;width:159px;height:60px;display:none;background:url(../img/icon.gif) no-repeat;padding:7px 10px 0;}
        #star p em{color:#f60;display:block;font-style:normal;}
    </style>
    <script type="text/javascript">

    </script>
</head>
<body>
<div id="star">
    <span>点击星星就能打分</span>
    <ul>
        <li><a href="javascript:;">1</a></li>
        <li><a href="javascript:;">2</a></li>
        <li><a href="javascript:;">3</a></li>
        <li><a href="javascript:;">4</a></li>
        <li><a href="javascript:;">5</a></li>
    </ul>
    <span></span>
    <p></p>
</div>

<script type="text/javascript">



    var oStar = document.getElementById("star");  //盒子DIV
    var aLi = oStar.getElementsByTagName("li");   //每一颗星星
    var oUl = oStar.getElementsByTagName("ul")[0];   //星星外围ul
    var oSpan = oStar.getElementsByTagName("span")[1];  //星星描述
    var oP = oStar.getElementsByTagName("p")[0];   //选定的星星
    var i = iScore = iStar = 0;
    var aMsg = [
        "很不满意|差得太离谱，与卖家描述的严重不符，非常不满",
        "不满意|部分有破损，与卖家描述的不符，不满意",
        "一般|质量一般，没有卖家描述的那么好",
        "满意|质量不错，与卖家描述的基本一致，还是挺满意的",
        "非常满意|质量非常好，与卖家描述的完全一致，非常满意"
    ];
    for(i=0;i<aLi.length;i++) {
        aLi[i].index = i;

        aLi[i].onmousemove = function() {  //每次移动到星星上面 就会显示下面的简介
            fnPoint(parseInt(this.index+1));
            oP.style.display = "block";     //显示简介
            oP.style.left = oUl.offsetLeft + this.index * this.offsetWidth - 84+'px';  //设置简介位置
            //以|分割 匹配两边的内容 并填充到p里面
            oP.innerHTML = "<em><b>"+ (parseInt(this.index+1)) +" </b> 分" + aMsg[this.index].match(/(.+)\|/)[1] + "</em>" + aMsg[this.index].match(/\|(.+)/)[1];
        }

        //鼠标离开
        aLi[i].onmouseout = function () {
            fnPoint();
            oP.style.display = "none";  //隐藏简介
        }

        //点击评分
        aLi[i].onclick = function() {
            iStar = parseInt(this.index+1);  //因为是从0循环的 所以要+1
            oP.style.display = "none";
            oSpan.innerHTML = "<strong>" + parseInt(this.index+1)  + " 分</strong> (" + aMsg[this.index].match(/\|(.+)/)[1] + ")";
    }

        //评分处理
        function fnPoint(iArg) {
            iScore = iArg || iStar;  //获取当前的下标
            for (i = 0; i < aLi.length; i++) aLi[i].className = i < iScore ? "on" : "";	  //小于当前下标的全部显示评分状态
        }


    }
</script>
</body>
</html>
